<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="MassageController.Massage.MassageBean" %>

<% 
/**** request의 캐릭터를 UTF-8로 변환시켜 받는 부분 ****/
request.setCharacterEncoding("UTF-8");

/**** 쪽지의 내용을 배열로 담아서 온 결과 값  ****/
MassageBean Out[] = (MassageBean[])request.getAttribute("Out");

/**** 
**	OutAll : 쪽지의 총 개수
**	OutPage : 현재 페이지 번호를 저장
**  OutPageArea : 현재 페이지의 영역을 저장
****/
int OutAll = (Integer)request.getAttribute("OutAll");
int OutPage = Integer.parseInt((String)request.getAttribute("OutPage"));
int OutPageArea = Integer.parseInt((String)request.getAttribute("OutPageArea"));

/**** 페이지당 뿌려질 쪽지 수를 구함 ****/
int Count = Out.length;

/**** 세션값이 세팅되어야 하는 부분으로 Nick이 세팅 되면 된다.  ****/
String sess = (String)session.getAttribute("Mem_Nick");

System.out.println("<페이지 부분 >  페이지 번호 = " + OutPage + " //// " + "총 페이지 수 = " + OutAll + " /// 페이지 에리어 = " + OutPageArea);

/**** All_page : 페이지의 총 수를 저장  ****/
int pageAll;
if ( OutAll % 10 == 0 ) {
	
	pageAll = ( int ) OutAll / 10;
	
}
else {
	
	pageAll = ( int ) OutAll / 10 + 1;
}
 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<!--   ***CSS파일 링크 부분***   -->
<link rel="stylesheet" type="text/css" href="/KOMORIUTA/css/Massage.css"> 

<title>Massage</title>
<script src="/KOMORIUTA/Massage/Ms_Script.js" type="text/JavaScript"></script>
<script src="/KOMORIUTA/Massage/jquery.js" type="text/JavaScript"></script>
<link rel="stylesheet" type="text/css" href="/KOMORIUTA/Mypage/Css/MpBord.css"> 
<meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5); charset=utf-8" />

</head>

<body>

<div align="center">

<form action="/KOMORIUTA/MassageServ.do" method="post" id="massage">
<input type="hidden" name="action" value="MsDelete">
<input type="hidden" name="id" value="<%=sess%>">
<input type="hidden" name="page" value="<%=OutPage%>">
<input type="hidden" name="pageArea" value="<%=OutPageArea%>">

<!--   ***가장 위의 MASSAGE부분***   -->
<table width="410" border="0">
  <tr>
    <td style="text-align: right">MASSAGE&nbsp;&nbsp;&nbsp;</td>
  </tr>
  <tr>
    <td><hr /></td>
  </tr>
</table>

<!--   ***Top부분***   -->
<div id="bbs">
	<div id="title">
    	<dl>
      	    <dt class="no"><input id="chAll" type="checkbox" onclick="CheckAll();" /></dt>
 			<dt class="writer">差出人</dt>
 			<dt class="title">内容</dt>
 			<dt class="hit"></dt>
        	<dt class="date">日付</dt>
        </dl>
    </div>
    <div id="main">
<%if(Count == 0){%>   
		<dl>
        	<dd class="all">Massageがありません。</dd>
        </dl>
	</div>	
<%}else{
	for(int i = 0;i < Count; i++){
%>
		<dl>
        	<dd class="no"> <label> 
				<input id="ch<%=i%>" name="ch<%=i%>" type="checkbox" class="delCheck"/>
          		<input type="hidden" name="chValue<%=i%>" value="<%=Out[i].getMagId()%>">
        	</label> </dd>
        	<dd class="writer"><%=Out[i].getMsgForm()%></dd>
        	<dd class="title">
				<div style="width:120px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; ">						
        			<a href=javascript:ScriptSee("<%=Out[i].getMagId()%>","<%=OutPage%>","<%=OutPageArea%>")><%=Out[i].getMsgContents()%></a>
 				</div>
        	</dd>
        	<dd class="hit">
        		<%if(Out[i].getMsgCheck() == 0){%>
 			  		<img src="/KOMORIUTA/Massage/image/New.gif" >
 				<%} %>
        	</dd>
			<dd class="date"><%=Out[i].getMsgDate()%></dd>
		</dl>
<%	}
}%>
	</div>
<table width="410"  border="0" cellpadding="4" cellspacing="0" >
	<tr>
		<td width=><input type="button" onclick="Del();" value="" class="btn_Dl"></td>
		<td align="center">
			<div id="foot">
<%
/**
* 페이징 부분
**/

if(OutPageArea >= 2){
	
	int backPage = (OutPageArea - 1) * 10;
	int backPageArea = OutPageArea - 1;
	out.print("<a href=javascript:PageGo('" + sess + "','" + backPage + "','" + backPageArea + "','" + session.getId() + "')>" + "[ ◀ ]</a>");
}

int a = (OutPageArea - 1) * 10 + 1;
int b = OutPageArea * 10;
	
if(b >= pageAll){
	int All = pageAll;
		for ( int j = a; j <= All; j++ ) { 
			out.print("<a href=javascript:PageGo('" + sess + "','" + j + "','" + OutPageArea + "','" + session.getId() + "')>" + " [" + j + "] </a>");
		}
	}else{
		for ( int j = a; j <= b; j++ ) { 
			out.print("<a href=javascript:PageGo('" + sess + "','" + j + "','" + OutPageArea + "','" + session.getId() + "')>" + " [" + j + "] </a>");
		}
		int nextPage = (OutPageArea * 10) + 1;
		int nextPageArea = OutPageArea + 1;
		out.print("<a href=javascript:PageGo('" + sess + "','" + nextPage + "','" + nextPageArea + "','" + session.getId() + "')>" + "[ ▶ ]</a>");
}
%>
			</div>
		</td>
		<td align="center" width="42">
			[<%=OutPage%>] Page
		</td>
	</tr>
</table>
</form>
</div>
</body>
</html>
